<template>
  <div>
    <van-picker title="性别" show-toolbar :columns="columns" @confirm="onConfirm" @cancel="onCancel"
      :default-index="value" />
  </div>
</template>

<script>
import { setUserInfos } from '@/api/user.js'
export default {
  data () {
    return {
      columns: ['男', '女'],
      gender: this.value
    }
  },
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  methods: {
    // 点击确认
    async onConfirm (val, index) {
      this.$toast.loading({
        message: '保存中...',
        forbidClick: true, // 禁止背景点击
        duration: 0 // 持续展示
      })
      try {
        await setUserInfos({
          gender: index
        })
        this.$toast('修改成功')
        // 更新视图
        this.$emit('input', index)
        // 关闭弹层
        this.$emit('close-popup')
      } catch (err) {
        this.$toast('修改失败')
      }
    },
    // 点击取消
    onCancel () {
      this.$emit('close-popup')
    },
    // 改变性别
    onChange () {

    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  created () { },
  mounted () { }
}
</script>

<style scoped lang='less'>
</style>
